home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-08-05 | 3.1 KB | 113 lines | [TEXT/PJMM] |
- {This VERY PRELIMINARY demo shows how to use different color tables with SAT,}
- {changing even after loading, and making sprite faces work with the changes.}
- {}
- {Usage: Type any key from 1 to 9 to choose CLUT. All CLUTs except 5 (the system palette)}
- {should leave the sprite intact, with the same colors. A small number of colors are used}
- {for the sprite face, and the others are changing in all the CLUTs.}
- {}
- {By Ingemar Ragnemalm 1996}
-
- program SATCluts;
- uses
- {$IFC UNDEFINED THINK_PASCAL}
- Types, QuickDraw, Menus, Windows, TextEdit, Fonts,
- Dialogs, Memory, Events, ToolUtils,{}
- {$ENDC}
- Palettes, QDOffScreen, SAT;
-
- procedure Nop (me: SpritePtr);
- begin
- end;
-
- procedure SATSetClut (theClut: CTabHandle);
- procedure CopyScreenClut (var p: SATPort);
- begin
- BlockMove(@gSAT.wind.device^^.gdPMap^^.pmTable^^, @p.device^^.gdPMap^^.pmTable^^, 8 + (p.device^^.gdPMap^^.pmTable^^.ctSize + 1) * 8);
- CTabChanged(gSAT.offScreen.device^^.gdPMap^^.pmTable);
- end; {CopyScreenClut}
- begin
- {Change screen CLUT}
- SATSetPortScreen;
- SetEntries(0, 255, theClut^^.ctTable);
- CTabChanged(gSAT.wind.device^^.gdPMap^^.pmTable);
- {Copy to all relevant offscreens}
- CopyScreenClut(gSAT.offScreen);
- CopyScreenClut(gSAT.backScreen);
- CopyScreenClut(gSAT.iconPort);
- CopyScreenClut(gSAT.iconPort2);
- {Fool CopyBits into believing that the CLUTs are identical - which they are!}
- CGrafPtr(gSAT.offScreen.port)^.portPixMap^^.pmTable^^.ctSeed := gSAT.wind.device^^.gdPMap^^.pmTable^^.ctSeed;
- CGrafPtr(gSAT.backScreen.port)^.portPixMap^^.pmTable^^.ctSeed := gSAT.wind.device^^.gdPMap^^.pmTable^^.ctSeed;
- CGrafPtr(gSAT.iconPort.port)^.portPixMap^^.pmTable^^.ctSeed := gSAT.wind.device^^.gdPMap^^.pmTable^^.ctSeed;
- CGrafPtr(gSAT.iconPort2.port)^.portPixMap^^.pmTable^^.ctSeed := gSAT.wind.device^^.gdPMap^^.pmTable^^.ctSeed;
- end;
-
- var
- myClut: array[1..10] of CTabHandle;
-
- var
- s: SpritePtr;
- theEvent: EventRecord;
- i: Integer;
- r: Rect;
-
- begin
- {$ifc UNDEFINED THINK_PASCAL}
- SATInitToolbox;
- {$endc}
-
- {Get the palettes we will switch between}
- for i := 1 to 10 do
- myClut[i] := GetCTable(127 + i);
-
- SATInit(0, 0, 640, 480);
- SATSetClut(myClut[1]);
- SATSetPortScreen;
- for i := 0 to 640 do
- begin
- RGBForeColor(myClut[1]^^.ctTable[i mod (myClut[1]^^.ctSize + 1)].rgb);
-
- MoveTo(i, 0);
- Line(0, 400);
- end;
- ForeColor(blackColor);
- SATSetPortBackscreen;
- for i := 0 to 640 do
- begin
- RGBForeColor(myClut[1]^^.ctTable[i mod (myClut[1]^^.ctSize + 1)].rgb);
-
- MoveTo(i, 0);
- Line(0, 400);
- end;
- ForeColor(blackColor);
- SATBackChanged(gSAT.wind.bounds);
-
- SATSetPortScreen;
-
- SATSetClut(myClut[10]); {A palette that inhibits all changing colors!}
-
- s := SATNewSprite(0, 0, 0, nil);
- s^.task := @Nop;
- s^.face := SATGetFace(128);
-
- {Set back to a "normal" CLUT}
- SATSetClut(myClut[1]);
-
- HideCursor;
- while not Button do
- begin
- SATRun(true);
- GetMouse(s^.position);
-
- if GetNextEvent(everyEvent, theEvent) then
- if theEvent.what = keyDown then
- case BitAnd(theEvent.message, 255) - Ord('0') of
- 1, 2, 3, 4, 5, 6, 7, 8, 9:
- SATSetClut(myClut[BitAnd(theEvent.message, 255) - Ord('0')]);
- otherwise
- end;
- end;
- ShowCursor;
-
- RestoreDeviceClut(nil);
- end.